<?php
namespace app\mini\controller\v1\client;

use app\common\model\CarBrands;
use app\mini\controller\Common;
use think\Env;
use think\Exception;

class CarBrand extends Common
{
    //品牌列表
    public function brand()
    {
        try{
            $data['hot_brand'] = CarBrands::getHotBrand();//热门品牌
            $data['all_brand'] = CarBrands::geAllBrands();//所有品牌
            return show(200, 'success', $data);
        }catch (Exception $e){
            return show(400, $e->getMessage(), [], self::$http_code);
        }
    }

    //品牌搜索
    public function search_brand()
    {
        try{
            $brand_name = input('name','');
            if (empty($brand_name)){
                self::$http_code = 200;
                throw new Exception("name不能为空");
            }
            $data = CarBrands::where(['name'=>['like','%'.$brand_name.'%']])->select()->toArray();
            if (!empty($data)){
                foreach ($data as &$v){
                    $v['logo'] = Env::get('app.app_host').$v['logo'];
                }
            }
            return show(200, 'success', $data);
        }catch (Exception $e){
            return show(self::$err_code, $e->getMessage(), [], self::$http_code);
        }
    }
}